package com.maikang.exammall.repository;

import com.maikang.exammall.entity.Commission;
import com.maikang.exammall.entity.dto.promote.StatusAmountOnly;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface CommissionRepository extends BaseRepository<Commission, Long>, JpaSpecificationExecutor<Commission> {

    @Modifying
    @Query("UPDATE Commission commission SET commission.status = :status WHERE commission.orderItemId IN (:itemIds)")
    void updateStatusByOrderItemIds(@Param("itemIds") List<Long> itemIds, @Param("status") Integer status);

    @Modifying
    @Query("UPDATE Commission commission SET commission.status = :status WHERE commission.orderId = :orderId")
    void updateStatusByOrderId(@Param("orderId") Long orderId, @Param("status") Integer status);

    List<StatusAmountOnly> findBySaleIdAndStatusBetween(Long saleId, Integer fromStatus, Integer toStatus);

    Slice<Commission> findBySaleIdAndStatusBetweenAndCreatedDateBetween(Long saleId, Integer fromStatus, Integer toStatus, Date fromDate, Date toDate, Pageable pageable);

}